import { singleton } from '@/utils/singleton'
import eventEmitter from '@/utils/eventEmitter'

function getUserInfo() {
    const info = uni.getStorageSync('userInfo')
    return info ? JSON.parse(info) : {}
}

class UserInfo {
    constructor() {
        this.infomation = getUserInfo()
    }
}

const UserInfoSingleton = singleton(UserInfo)
const userInfoInstance = new UserInfoSingleton()

eventEmitter.on('STORAGE:USERINFO_CHANGE', () => {
    userInfoInstance.infomation = getUserInfo()
})

export default userInfoInstance